#!/usr/bin/make -f

MAJOR_VER := 6

include /usr/share/dpkg/architecture.mk
include /usr/share/dpkg/pkg-info.mk

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_CFLAGS_MAINT_APPEND = -Wno-error=implicit-fallthrough

%:
	dh $@

override_dh_autoreconf:
	dh_autoreconf ./debian/autoreconf.sh

# TODO: how to properly clean gpdb source
override_dh_auto_clean:

override_dh_auto_configure:
	dh_auto_configure -- \
            --prefix=/usr/local/greenplum-db-$(MAJOR_VER) \
            --disable-rpath \
            --disable-tap-tests \
            --disable-gpperfmon \
            --with-gssapi \
            --enable-mapreduce \
            --enable-orafce \
            --enable-orca \
            --with-libxml \
            --with-pgport=5432 \
            --with-libedit-preferred \
            --disable-debug-extensions \
            --with-perl \
            --with-python \
            --with-openssl \
            --with-pam \
            --with-ldap \
            --enable-debug \
            --with-system-tzdata=/usr/share/zoneinfo \
            --with-pythonsrc-ext
	dh_auto_configure --sourcedirectory=gpAux/extensions/pgbouncer/source -- \
	    --prefix=/usr/local/greenplum-db-$(MAJOR_VER) \
	    --with-libevent \
	    --with-pam \
	    --enable-evdns

override_dh_auto_build:
	dh_auto_build
	dh_auto_build --sourcedirectory=gpAux/extensions/pgbouncer/source

override_dh_shlibdeps:
	dh_shlibdeps -l /usr/local/greenplum-db-$(MAJOR_VER)/lib/$(DEB_TARGET_MULTIARCH)

override_dh_auto_install:
	dh_auto_install
	dh_auto_install --sourcedirectory=gpAux/extensions/pgbouncer/source

# TODO: how to test
override_dh_auto_test:

# disable dh_usrlocal since we are installing there
override_dh_usrlocal:

override_dh_fixperms:
	dh_fixperms
	chmod -x \
		debian/greenplum-db-$(MAJOR_VER)/usr/local/greenplum-db-$(MAJOR_VER)/bin/gpcheckcat_modules/__init__.py \
		debian/greenplum-db-$(MAJOR_VER)/usr/local/greenplum-db-$(MAJOR_VER)/bin/gpcheckcat_modules/leaked_schema_dropper.py \
		debian/greenplum-db-$(MAJOR_VER)/usr/local/greenplum-db-$(MAJOR_VER)/bin/gpconfig_modules/__init__.py \
		debian/greenplum-db-$(MAJOR_VER)/usr/local/greenplum-db-$(MAJOR_VER)/bin/gpconfig_modules/compare_segment_guc.py \
		debian/greenplum-db-$(MAJOR_VER)/usr/local/greenplum-db-$(MAJOR_VER)/bin/gpconfig_modules/database_segment_guc.py \
		debian/greenplum-db-$(MAJOR_VER)/usr/local/greenplum-db-$(MAJOR_VER)/bin/gpconfig_modules/file_segment_guc.py \
		debian/greenplum-db-$(MAJOR_VER)/usr/local/greenplum-db-$(MAJOR_VER)/bin/gpconfig_modules/guc_collection.py \
		debian/greenplum-db-$(MAJOR_VER)/usr/local/greenplum-db-$(MAJOR_VER)/bin/gpconfig_modules/parse_guc_metadata.py \
		debian/greenplum-db-$(MAJOR_VER)/usr/local/greenplum-db-$(MAJOR_VER)/bin/gpconfig_modules/segment_guc.py \
		debian/greenplum-db-$(MAJOR_VER)/usr/local/greenplum-db-$(MAJOR_VER)/bin/gpssh_modules/__init__.py \
		debian/greenplum-db-$(MAJOR_VER)/usr/local/greenplum-db-$(MAJOR_VER)/bin/gpssh_modules/gppxssh_wrapper.py \
		debian/greenplum-db-$(MAJOR_VER)/usr/local/greenplum-db-$(MAJOR_VER)/bin/lib/__init__.py \
		debian/greenplum-db-$(MAJOR_VER)/usr/local/greenplum-db-$(MAJOR_VER)/bin/lib/gp_bash_version.sh \
		debian/greenplum-db-$(MAJOR_VER)/usr/local/greenplum-db-$(MAJOR_VER)/bin/lib/pexpect/__init__.py \
		debian/greenplum-db-$(MAJOR_VER)/usr/local/greenplum-db-$(MAJOR_VER)/bin/lib/pexpect/pxssh.py \
		debian/greenplum-db-$(MAJOR_VER)/usr/local/greenplum-db-$(MAJOR_VER)/lib/$(DEB_TARGET_MULTIARCH)/postgresql/pgxs/src/test/regress/GPTest.pm \
		debian/greenplum-db-$(MAJOR_VER)/usr/local/greenplum-db-$(MAJOR_VER)/lib/$(DEB_TARGET_MULTIARCH)/postgresql/pgxs/src/test/regress/atmsort.pm \
		debian/greenplum-db-$(MAJOR_VER)/usr/local/greenplum-db-$(MAJOR_VER)/lib/$(DEB_TARGET_MULTIARCH)/postgresql/pgxs/src/test/regress/explain.pm \
		debian/greenplum-db-$(MAJOR_VER)/usr/local/greenplum-db-$(MAJOR_VER)/lib/$(DEB_TARGET_MULTIARCH)/python/gppylib/operations/test_utils_helper.py \
		debian/greenplum-db-$(MAJOR_VER)/usr/local/greenplum-db-$(MAJOR_VER)/lib/$(DEB_TARGET_MULTIARCH)/python/gppylib/programs/gppkg.py \
		debian/greenplum-db-$(MAJOR_VER)/usr/local/greenplum-db-$(MAJOR_VER)/sbin/recovery_base.py
